package pro.shuangxi.model.book.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import mybatisplus.pojo.Account;
import mybatisplus.pojo.BookHistory;
import mybatisplus.service.IAccountService;
import mybatisplus.service.IBookHistoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import pro.shuangxi.common.vo.Result;
import pro.shuangxi.model.book.helper.book.BookRepository;
import pro.shuangxi.model.book.pojo.Story;

import java.util.HashMap;

/**
     * @author ：mengshx
     * @date ：Created in 2020/11/29 10:29
     * @description：阅读器
     */
    @Controller
    public class ReaderController {
        @Autowired
        IAccountService accountService;

        @Autowired
         IBookHistoryService bookHistoryService;


        private HashMap<String, Account> tokens = new HashMap<>();
        @Autowired
        private BookRepository bookRepository;

    @RequestMapping(value="nextPage.do",produces = "text/html;charset=utf-8")
    @ResponseBody
    public String nextPage(@RequestParam("page") int page,
                           @RequestParam(value="book")Integer bookid) {
        if (bookid < 0) {
            return "请选择小说";
        }
        Story story = bookRepository.getOneById(bookid);
        Account account=null;

        return  story.readPage(page);
    }
    @RequestMapping(value="queryPage.do")
    @ResponseBody
    public Result queryPage(@RequestParam(value="accountid",required = false) String accountid,
                            @RequestParam(value="book",required = false) String bookid) {
                    BookHistory history = bookHistoryService.getOne(new QueryWrapper<BookHistory>().eq("accountid", accountid).eq("bookid", "bookid"));
        return Result.OK(history);
    }

}
